<template>
  <div class="support-wraper">
    <header>
      <div
        v-for="(item, index) in serviceList"
        :key="index"
        :class="{active: tabsActive === item.value}"
        @click="tabsHandle(item.value)"
      >
        {{ item.name }}
      </div>
    </header>
    <main>
      <div v-for="(item, index) in supportList" :key="index">
        <titleBar :titleText="item.title"></titleBar>
        <el-editable
          :key="item.title + index"
          :stripe="false"
          :data="item.list || []"
          :columns="tableColumn"
          height="auto"
        />
      </div>
    </main>
  </div>
</template>

<script>
import {workbenchCustomerSupportist} from '@const/mDataCenterApi.js'
import {AcOverallStructureorkbenchTable} from '@const/api_authCenter.js'
import ElEditable from '@components/el-editable/index.vue'
import titleBar from '@/moduleComponents/newWorkbench/titleBar'
import {tableColumn} from './const'
export default {
  name: 'CustomerSupportList',
  components: {
    ElEditable,
    titleBar
  },
  data() {
    return {
      serviceList: [],
      supportList: [],
      tableData: [],
      tableColumn,
      titleText: 'erer',
      tabsActive: null,
      tabKey: ''
    }
  },
  created() {
    this.tabsActive = this.$route.query.tabKey
    this.initLayout()
    this.getServiceList()
    this.getSupportList()
  },
  methods: {
    // 初始化右上角的按钮
    initLayout() {
      let obj = {
        type: 'btn',
        arr: [
          {
            val: '返回',
            icon: 'el-icon-arrow-left',
            handle: this.back
          }
        ]
      }
      this.$store.commit('changeLayoutHandle', obj)
    },
    back() {
      this.$router.go(-1)
    },
    // tab切换
    tabsHandle(tabValue) {
      this.tabsActive = tabValue
      this.getSupportList()
    },
    // 获取页签
    getServiceList() {
      this.$axios({
        url: AcOverallStructureorkbenchTable,
        method: 'post'
      })
        .then(res => {
          this.serviceList = res.data.payload || []
        })
        .catch(err => {
          console.log(err)
        })
    },
    // 获取列表
    getSupportList() {
      this.$axios({
        url: workbenchCustomerSupportist,
        method: 'post',
        data: {
          areaType: this.tabsActive
        }
      })
        .then(res => {
          console.log(res, 'supportList')
          this.supportList = res.data.payload || []
        })
        .catch(err => {
          console.log(err)
        })
    }
  }
}
</script>

<style scoped lang="less">
.support-wraper {
  position: unset !important;
}
header {
  height: 57px;
  border: 1px solid rgba(233, 233, 233, 1);
  font-size: 14px;
  color: #909db0;
  background: #fff;
  user-select: none;
  display: flex;
  justify-content: flex-start;
  align-items: center;
  div {
    height: 100%;
    text-align: center;
    line-height: 57px;
    padding: 0 16px;
    box-sizing: border-box;
    position: relative;
    cursor: pointer;
  }
  div.active {
    font-size: 20px;
    color: #2371c5;
    font-weight: 500;
  }
  div.active::after {
    content: '';
    height: 2px;
    width: calc(100% - 32px);
    background: #2371c5;
    position: absolute;
    bottom: 0;
    left: 16px;
  }
}
</style>
